<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en" dir="ltr" class="client-nojs">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>signal - cppreference.com</title>
<meta charset="UTF-8">
<meta name="generator" content="MediaWiki 1.21.2">


<link rel="shortcut icon" href="../../../favicon.ico">



<link rel="stylesheet" href="../../../common/ext.css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" href="../../../common/site_modules.css">
<style>a:lang(ar),a:lang(ckb),a:lang(fa),a:lang(kk-arab),a:lang(mzn),a:lang(ps),a:lang(ur){text-decoration:none}#toc{display:none}.editsection{display:none}
/* cache key: mwiki1-mwiki_en_:resourceloader:filter:minify-css:7:472787eddcf4605d11de8c7ef047234f */</style>

<script src="../../../common/startup_scripts.js"></script>
<script>if(window.mw){
mw.config.set({"wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"c/program/signal","wgTitle":"c/program/signal","wgCurRevisionId":69680,"wgArticleId":6183,"wgIsArticle":true,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":[],"wgBreakFrames":false,"wgPageContentLanguage":"en","wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgMonthNamesShort":["","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"wgRelevantPageName":"c/program/signal","wgRestrictionEdit":[],"wgRestrictionMove":[]});
}</script><script>if(window.mw){
mw.loader.implement("user.options",function(){mw.user.options.set({"ccmeonemails":0,"cols":80,"date":"default","diffonly":0,"disablemail":0,"disablesuggest":0,"editfont":"default","editondblclick":0,"editsection":0,"editsectiononrightclick":0,"enotifminoredits":0,"enotifrevealaddr":0,"enotifusertalkpages":1,"enotifwatchlistpages":0,"extendwatchlist":0,"externaldiff":0,"externaleditor":0,"fancysig":0,"forceeditsummary":0,"gender":"unknown","hideminor":0,"hidepatrolled":0,"imagesize":2,"justify":0,"math":1,"minordefault":0,"newpageshidepatrolled":0,"nocache":0,"noconvertlink":0,"norollbackdiff":0,"numberheadings":0,"previewonfirst":0,"previewontop":1,"quickbar":5,"rcdays":7,"rclimit":50,"rememberpassword":0,"rows":25,"searchlimit":20,"showhiddencats":0,"showjumplinks":1,"shownumberswatching":1,"showtoc":0,"showtoolbar":1,"skin":"cppreference2","stubthreshold":0,"thumbsize":2,"underline":2,"uselivepreview":0,"usenewrc":0,"watchcreations":0,"watchdefault":0,"watchdeletion":0,
"watchlistdays":3,"watchlisthideanons":0,"watchlisthidebots":0,"watchlisthideliu":0,"watchlisthideminor":0,"watchlisthideown":0,"watchlisthidepatrolled":0,"watchmoves":0,"wllimit":250,"variant":"en","language":"en","searchNs0":true,"searchNs1":false,"searchNs2":false,"searchNs3":false,"searchNs4":false,"searchNs5":false,"searchNs6":false,"searchNs7":false,"searchNs8":false,"searchNs9":false,"searchNs10":false,"searchNs11":false,"searchNs12":false,"searchNs13":false,"searchNs14":false,"searchNs15":false,"gadget-ColiruCompiler":1});;},{},{});mw.loader.implement("user.tokens",function(){mw.user.tokens.set({"editToken":"+\\","patrolToken":false,"watchToken":false});;},{},{});
/* cache key: mwiki1-mwiki_en_:resourceloader:filter:minify-js:7:ca03345b1e2c4d90a25d968753a73b92 */
}</script>
<script>if(window.mw){
mw.loader.load(["mediawiki.page.startup","mediawiki.legacy.wikibits","mediawiki.legacy.ajax"]);
}</script>
<style type="text/css">/*<![CDATA[*/
.source-c {line-height: normal;}
.source-c li, .source-c pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for c
 * CSS class: source-c, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.c.source-c .de1, .c.source-c .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.c.source-c  {font-family:monospace;}
.c.source-c .imp {font-weight: bold; color: red;}
.c.source-c li, .c.source-c .li1 {font-weight: normal; vertical-align:top;}
.c.source-c .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.c.source-c .li2 {font-weight: bold; vertical-align:top;}
.c.source-c .kw1 {color: #0000dd;}
.c.source-c .kw2 {color: #0000ff;}
.c.source-c .kw3 {color: #0000dd;}
.c.source-c .kw4 {color: #0000ff;}
.c.source-c .co1 {color: #909090;}
.c.source-c .co2 {color: #339900;}
.c.source-c .coMULTI {color: #ff0000; font-style: italic;}
.c.source-c .es0 {color: #008000; font-weight: bold;}
.c.source-c .es1 {color: #008000; font-weight: bold;}
.c.source-c .es2 {color: #008000; font-weight: bold;}
.c.source-c .es3 {color: #008000; font-weight: bold;}
.c.source-c .es4 {color: #008000; font-weight: bold;}
.c.source-c .es5 {color: #008000; font-weight: bold;}
.c.source-c .br0 {color: #008000;}
.c.source-c .sy0 {color: #008000;}
.c.source-c .sy1 {color: #000080;}
.c.source-c .sy2 {color: #000040;}
.c.source-c .sy3 {color: #000040;}
.c.source-c .sy4 {color: #008080;}
.c.source-c .st0 {color: #008000;}
.c.source-c .nu0 {color: #000080;}
.c.source-c .nu6 {color:#000080;}
.c.source-c .nu8 {color:#000080;}
.c.source-c .nu12 {color:#000080;}
.c.source-c .nu16 {color:#000080;}
.c.source-c .nu17 {color:#000080;}
.c.source-c .nu18 {color:#000080;}
.c.source-c .nu19 {color:#000080;}
.c.source-c .ln-xtra, .c.source-c li.ln-xtra, .c.source-c div.ln-xtra {background-color: #ffc;}
.c.source-c span.xtra { display:block; }

/*]]>*/
</style>
<style type="text/css">/*<![CDATA[*/
.source-text {line-height: normal;}
.source-text li, .source-text pre {
	line-height: normal; border: 0px none white;
}
/**
 * GeSHi Dynamically Generated Stylesheet
 * --------------------------------------
 * Dynamically generated stylesheet for text
 * CSS class: source-text, CSS id: 
 * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann
 * (http://qbnz.com/highlighter/ and http://geshi.org/)
 * --------------------------------------
 */
.text.source-text .de1, .text.source-text .de2 {font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;}
.text.source-text  {font-family:monospace;}
.text.source-text .imp {font-weight: bold; color: red;}
.text.source-text li, .text.source-text .li1 {font-weight: normal; vertical-align:top;}
.text.source-text .ln {width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;}
.text.source-text .li2 {font-weight: bold; vertical-align:top;}
.text.source-text .ln-xtra, .text.source-text li.ln-xtra, .text.source-text div.ln-xtra {background-color: #ffc;}
.text.source-text span.xtra { display:block; }

/*]]>*/
</style>
<!--[if lt IE 7]><style type="text/css">body{behavior:url("/mwiki/skins/cppreference2/csshover.min.htc")}</style><![endif]-->
</head>
<body class="mediawiki ltr sitedir-ltr ns-0 ns-subject page-c_program_signal skin-cppreference2 action-view cpp-navbar">
        <!-- header -->
        
        <!-- /header -->
        <!-- content -->
        <div id="cpp-content-base">
            <div id="content">
                <a id="top"></a>
                <div id="mw-js-message" style="display:none;"></div>
                                <!-- firstHeading -->
                <h1 id="firstHeading" class="firstHeading">signal</h1>
                <!-- /firstHeading -->
                <!-- bodyContent -->
                <div id="bodyContent">
                                        <!-- tagline -->
                    <div id="siteSub">From cppreference.com</div>
                    <!-- /tagline -->
                                        <!-- subtitle -->
                    <div id="contentSub"><span class="subpages">&lt; <a href="../../c.html" title="c">c</a>‎ | <a href="../program.html" title="c/program">program</a></span></div>
                    <!-- /subtitle -->
                                                            <!-- bodycontent -->
                    <div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr">
<div class="t-navbar" style="">
<div class="t-navbar-sep"> </div>
<div class="t-navbar-head">
<a href="../../c.html" title="c"> C</a><div class="t-navbar-menu"><div>
<div><table class="t-nv-begin" cellpadding="0" style="line-height:1.1em;">
<tr class="t-nv"><td colspan="5"> <a href="../language.1.html" title="c/language"> Language</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../header.html" title="c/header"> Standard Library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../types.html" title="c/types"> Type support</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../memory.html" title="c/memory"> Dynamic memory management</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../error.html" title="c/error"> Error handling</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../program.html" title="c/program"> Program utilities</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../chrono.html" title="c/chrono"> Date and time utilities</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../string.html" title="c/string"> Strings library</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../algorithm.html" title="c/algorithm"> Algorithms</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../numeric.html" title="c/numeric"> Numerics</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../io.html" title="c/io"> Input/output support</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../locale.html" title="c/locale"> Localization support</a> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../thread.html" title="c/thread"> Thread support</a> <span class="t-mark-rev t-since-c11">(C11)</span> </td></tr>
<tr class="t-nv"><td colspan="5"> <a href="../atomic.html" title="c/atomic"> Atomic operations</a> <span class="t-mark-rev t-since-c11">(C11)</span> </td></tr>
</table></div>
<div></div>
</div></div>
</div>
<div class="t-navbar-sep"> </div>
<div class="t-navbar-head">
<a href="../program.html" title="c/program"> Program support utilities</a><div class="t-navbar-menu"><div>
<div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv-h1"><td colspan="5"> Program termination</td></tr>
<tr class="t-nv-col-table">
<td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="abort.html" title="c/program/abort"><span class="t-lines"><span>abort</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="exit.html" title="c/program/exit"><span class="t-lines"><span>exit</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table">
<div><a href="quick_exit.html" title="c/program/quick exit"><span class="t-lines"><span>quick_exit</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table">
<div><a href="_Exit.html" title="c/program/ Exit"><span class="t-lines"><span>_Exit</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div></td></tr>
</table></div></td>
<td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="atexit.html" title="c/program/atexit"><span class="t-lines"><span>atexit</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table">
<div><a href="at_quick_exit.html" title="c/program/at quick exit"><span class="t-lines"><span>at_quick_exit</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-cxx11">(C++11)</span></span></span></div>
</div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="EXIT_status.html" title="c/program/EXIT status"><span class="t-lines"><span>EXIT_SUCCESS</span><span>EXIT_FAILURE</span></span></a></div></div></td></tr>
</table></div></td>
</tr>
<tr class="t-nv-h1"><td colspan="5"> Communicating with the environment</td></tr>
<tr class="t-nv-col-table">
<td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="system.html" title="c/program/system"><span class="t-lines"><span>system</span></span></a></div></div></td></tr>
</table></div></td>
<td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="getenv.html" title="c/program/getenv"><span class="t-lines"><span>getenv</span></span></a></div></div></td></tr>
</table></div></td>
</tr>
<tr class="t-nv-h1"><td colspan="5"> Signals</td></tr>
<tr class="t-nv-col-table">
<td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><strong class="selflink"><span class="t-lines"><span>signal</span></span></strong></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="raise.html" title="c/program/raise"><span class="t-lines"><span>raise</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="sig_atomic_t.html" title="c/program/sig atomic t"><span class="t-lines"><span>sig_atomic_t</span></span></a></div></div></td></tr>
</table></div></td>
<td><div><table class="t-nv-begin" cellpadding="0" style="">
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="SIG_strategies.html" title="c/program/SIG strategies"><span class="t-lines"><span>SIG_DFL</span><span>SIG_IGN</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="SIG_ERR.html" title="c/program/SIG ERR"><span class="t-lines"><span>SIG_ERR</span></span></a></div></div></td></tr>
</table></div></td>
</tr>
<tr class="t-nv-h2"><td colspan="5"> Signal types</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="SIG_types.html" title="c/program/SIG types"><span class="t-lines"><span>SIGABRT</span><span>SIGFPE</span><span>SIGILL</span><span>SIGINT</span><span>SIGSEGV</span><span>SIGTERM</span></span></a></div></div></td></tr>
<tr class="t-nv-h1"><td colspan="5"> Non-local jumps</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="setjmp.html" title="c/program/setjmp"><span class="t-lines"><span>setjmp</span></span></a></div></div></td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="longjmp.html" title="c/program/longjmp"><span class="t-lines"><span>longjmp</span></span></a></div></div></td></tr>
<tr class="t-nv-h2"><td colspan="5"> Types</td></tr>
<tr class="t-nv"><td colspan="5"><div class="t-nv-ln-table"><div><a href="jmp_buf.html" title="c/program/jmp buf"><span class="t-lines"><span>jmp_buf</span></span></a></div></div></td></tr>
</table></div>
<div></div>
</div></div>
</div>
<div class="t-navbar-sep"> </div>
</div>
<table class="t-dcl-begin"><tbody>
<tr class="t-dsc-header">
<td> <div>Defined in header <code>&lt;signal.h&gt;</code>
 </div>
</td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl">
<td class="t-dcl-nopad"> <div><span class="mw-geshi c source-c"><span class="kw4">void</span> <span class="br0">(</span><span class="sy2">*</span>signal<span class="br0">(</span> <span class="kw4">int</span> sig, <span class="kw4">void</span> <span class="br0">(</span><span class="sy2">*</span>handler<span class="br0">)</span> <span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span><span class="br0">)</span><span class="br0">)</span> <span class="br0">(</span><span class="kw4">int</span><span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td class="t-dcl-nopad">  </td>
<td class="t-dcl-nopad">  </td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
<p>Sets the error handler for signal <code>sig</code>. The signal handler can be set so that default handling will occur, signal is ignored, or an user-defined function is called.
</p>
<p>When signal handler is set to a function and a signal occurs, it is implementation defined whether <span class="t-c"><span class="mw-geshi c source-c">signal<span class="br0">(</span>sig, <a href="SIG_strategies.html"><span class="kw499">SIG_DFL</span></a><span class="br0">)</span></span></span> will be executed immediately before the start of signal handler. Also, the implementation can prevent some implementation-defined set af signals from occurring while the signal handler runs.
</p>
<table id="toc" class="toc"><tr><td>
<div id="toctitle"><h2>Contents</h2></div>
<ul>
<li class="toclevel-1 tocsection-1"><a href="signal.html%23Parameters"><span class="tocnumber">1</span> <span class="toctext">Parameters</span></a></li>
<li class="toclevel-1 tocsection-2"><a href="signal.html%23Return_value"><span class="tocnumber">2</span> <span class="toctext">Return value</span></a></li>
<li class="toclevel-1 tocsection-3"><a href="signal.html%23Signal_handler"><span class="tocnumber">3</span> <span class="toctext">Signal handler</span></a></li>
<li class="toclevel-1 tocsection-4"><a href="signal.html%23Notes"><span class="tocnumber">4</span> <span class="toctext">Notes</span></a></li>
<li class="toclevel-1 tocsection-5"><a href="signal.html%23Example"><span class="tocnumber">5</span> <span class="toctext">Example</span></a></li>
<li class="toclevel-1 tocsection-6"><a href="signal.html%23See_also"><span class="tocnumber">6</span> <span class="toctext">See also</span></a></li>
</ul>
</td></tr></table>
<h3>
<span class="editsection">[<a href="http%3A//en.cppreference.com/mwiki/index.php" title="Edit section: Parameters">edit</a>]</span> <span class="mw-headline" id="Parameters">Parameters</span>
</h3>
<table class="t-par-begin">


<tr class="t-par">
<td>  sig
</td>
<td> -
</td>
<td>  the signal to set the signal handler to. It can be an implementation-defined value or one of the following values:
<table class="t-dsc-begin">

<tr class="t-dsc-sep">
<td colspan="2">
</td>
</tr>
<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="SIG_types.html" title="c/program/SIG types"> <span class="t-lines"><span>SIGABRT</span><span>SIGFPE</span><span>SIGILL</span><span>SIGINT</span><span>SIGSEGV</span><span>SIGTERM</span></span></a></div></div>
</td>
<td>   defines signal types <br> <span class="t-mark">(macro constant)</span> 
</td>
</tr>
</table>
<p><br>
</p>
</td>
</tr>
<tr class="t-par">
<td>  handler
</td>
<td> -
</td>
<td>  the signal handler. This must be one of the following:
<ul>
<li>
<span class="t-lc"><a href="SIG_strategies.html" title="c/program/SIG strategies">SIG_DFL</a></span> macro. The signal handler is set to default signal handler.
</li>
<li>
<span class="t-lc"><a href="SIG_strategies.html" title="c/program/SIG strategies">SIG_IGN</a></span> macro. The signal is ignored.
</li>
<li>pointer to a function. The signature of the function must be equivalent to the following:
</li>
</ul>
<table class="t-dcl-begin"><tbody>

<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
<tr class="t-dcl">
<td class="t-dcl-nopad"> <div><span class="mw-geshi c source-c"><span class="kw4">void</span> fun<span class="br0">(</span><span class="kw4">int</span> sig<span class="br0">)</span><span class="sy4">;</span></span></div>
</td>
<td class="t-dcl-nopad">  </td>
<td class="t-dcl-nopad">  </td>
</tr>
<tr class="t-dcl-sep">
<td></td>
<td></td>
<td></td>
</tr>
</tbody></table>
</td>
</tr>
</table>
<h3>
<span class="editsection">[<a href="http%3A//en.cppreference.com/mwiki/index.php" title="Edit section: Return value">edit</a>]</span> <span class="mw-headline" id="Return_value">Return value</span>
</h3>
<p>Previous signal handler on success or <span class="t-lc"><a href="SIG_ERR.html" title="c/program/SIG ERR">SIG_ERR</a></span> on failure (setting a signal handler can be disabled on some implementations).
</p>
<h3>
<span class="editsection">[<a href="http%3A//en.cppreference.com/mwiki/index.php" title="Edit section: Signal handler">edit</a>]</span> <span class="mw-headline" id="Signal_handler">Signal handler</span>
</h3>
<p>The following limitations are imposed on the user-defined function that is installed as a signal handle
</p>
<p>If the user defined function returns when handling <span class="t-lc"><a href="SIG_types.html" title="c/program/SIG types">SIGFPE</a></span>, <span class="t-lc"><a href="SIG_types.html" title="c/program/SIG types">SIGILL</a></span> or <span class="t-lc"><a href="SIG_types.html" title="c/program/SIG types">SIGSEGV</a></span>, the behavior is undefined.
</p>
<p>If the signal handler is called as a result of <span class="t-lc"><a href="abort.html" title="c/program/abort">abort</a></span> or <span class="t-lc"><a href="raise.html" title="c/program/raise">raise</a></span>, the behavior is undefined if the signal handler calls <span class="t-lc"><a href="raise.html" title="c/program/raise">raise</a></span>.
</p>
<p>If the signal handler is called NOT as a result of <span class="t-lc"><a href="abort.html" title="c/program/abort">abort</a></span> or <span class="t-lc"><a href="raise.html" title="c/program/raise">raise</a></span>, the behavior is undefined if
</p>
<ul>
<li> the signal handler calls any function within the standard library, except <span class="t-lc"><a href="abort.html" title="c/program/abort">abort</a></span>, <span class="t-lc"><a href="_Exit.html" title="c/program/ Exit">_Exit</a></span>, <span class="t-lc"><a href="quick_exit.html" title="c/program/quick exit">quick_exit</a></span>, or <span class="t-c"><span class="mw-geshi c source-c">signal</span></span> with the first argument not being the number of the signal currently handled. 
</li>
<li> the signal handler refers to any object with static or thread-local<span class="t-mark-rev t-since-c11">(since C11)</span> storage duration that is not lock-free atomic<span class="t-mark-rev t-since-c11">(since C11)</span> or <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">volatile</span> std<span class="sy4">::</span><a href="sig_atomic_t.html"><span class="kw498">sig_atomic_t</span></a></span></span>.
</li>
</ul>
<p>On entry to the signal handler, the state of the floating-point environment and the values of all objects is unspecified, except for
</p>
<ul>
<li> objects of type <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw498">sig_atomic_t</span></a></span></span>
</li>
<li> objects of lock-free atomic types <span class="t-mark-rev t-since-c11">(since C11)</span>
</li>
<li> side effects made visible through <span class="t-lc"><a href="../atomic/atomic_signal_fence.html" title="c/atomic/atomic signal fence">atomic_signal_fence</a></span> <span class="t-mark-rev t-since-c11">(since C11)</span>
</li>
</ul>
<p>On return from a signal handler, the value of any object modified by the signal handler that is not <span class="t-c"><span class="mw-geshi c source-c"><span class="kw4">volatile</span> <a href="sig_atomic_t.html"><span class="kw498">sig_atomic_t</span></a></span></span> or lock-free atomic<span class="t-mark-rev t-since-c11">(since C11)</span> is undefined.
</p>
<p>The behavior is undefined if <span class="t-c"><span class="mw-geshi c source-c">signal</span></span> is used in a multithreaded program. It is not required to be thread-safe.
</p>
<h3>
<span class="editsection">[<a href="http%3A//en.cppreference.com/mwiki/index.php" title="Edit section: Notes">edit</a>]</span> <span class="mw-headline" id="Notes">Notes</span>
</h3>
<p>POSIX requires that <code>signal</code> is thread-safe, and <a rel="nofollow" class="external text" href="http%3A//pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html%23tag_15_04">specifies a list of async-signal-safe library functions</a> that may be called from any signal handler.
</p>
<h3>
<span class="editsection">[<a href="http%3A//en.cppreference.com/mwiki/index.php" title="Edit section: Example">edit</a>]</span> <span class="mw-headline" id="Example">Example</span>
</h3>
<div class="t-example">
<div class="t-example-live-link"><div class="coliru-btn coliru-btn-run-init">Run this code</div></div>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="c source-c"><pre class="de1"><span class="co2">#include &lt;stdio.h&gt;</span>
<span class="co2">#include &lt;signal.h&gt;</span>
 
<span class="coMULTI">/* A user-defined signal handler can process one or more signals. */</span>
<span class="kw4">static</span> <span class="kw4">void</span> signal_handler<span class="br0">(</span><span class="kw4">int</span> signo<span class="br0">)</span>
<span class="br0">{</span>
    <span class="kw1">switch</span><span class="br0">(</span>signo<span class="br0">)</span>
    <span class="br0">{</span>
        <span class="kw1">case</span> <a href="SIG_types.html"><span class="kw502">SIGABRT</span></a> <span class="sy4">:</span> <a href="../io/puts.html"><span class="kw835">puts</span></a><span class="br0">(</span><span class="st0">"Process SIGABRT signal here."</span><span class="br0">)</span><span class="sy4">;</span> <span class="kw1">break</span><span class="sy4">;</span>
        <span class="kw1">case</span> <a href="SIG_types.html"><span class="kw503">SIGFPE</span></a>  <span class="sy4">:</span> <a href="../io/puts.html"><span class="kw835">puts</span></a><span class="br0">(</span><span class="st0">"Process SIGFPE  signal here."</span><span class="br0">)</span><span class="sy4">;</span> <span class="kw1">break</span><span class="sy4">;</span>
        <span class="kw1">case</span> <a href="SIG_types.html"><span class="kw504">SIGILL</span></a>  <span class="sy4">:</span> <a href="../io/puts.html"><span class="kw835">puts</span></a><span class="br0">(</span><span class="st0">"Process SIGILL  signal here."</span><span class="br0">)</span><span class="sy4">;</span> <span class="kw1">break</span><span class="sy4">;</span>
        <span class="kw1">case</span> <a href="SIG_types.html"><span class="kw505">SIGINT</span></a>  <span class="sy4">:</span> <a href="../io/puts.html"><span class="kw835">puts</span></a><span class="br0">(</span><span class="st0">"Process SIGINT  signal here."</span><span class="br0">)</span><span class="sy4">;</span> <span class="kw1">break</span><span class="sy4">;</span>
        <span class="kw1">case</span> <a href="SIG_types.html"><span class="kw506">SIGSEGV</span></a> <span class="sy4">:</span> <a href="../io/puts.html"><span class="kw835">puts</span></a><span class="br0">(</span><span class="st0">"Process SIGSEGV signal here."</span><span class="br0">)</span><span class="sy4">;</span> <span class="kw1">break</span><span class="sy4">;</span>
        <span class="kw1">case</span> <a href="SIG_types.html"><span class="kw507">SIGTERM</span></a> <span class="sy4">:</span> <a href="../io/puts.html"><span class="kw835">puts</span></a><span class="br0">(</span><span class="st0">"Process SIGTERM signal here."</span><span class="br0">)</span><span class="sy4">;</span> <span class="kw1">break</span><span class="sy4">;</span>
    <span class="br0">}</span>
 
    <span class="coMULTI">/* some cleanup here */</span>
    <span class="coMULTI">/* exit(signo);      */</span>
<span class="br0">}</span>
 
<span class="kw4">int</span> main<span class="br0">(</span><span class="kw4">void</span><span class="br0">)</span>
<span class="br0">{</span>
    <span class="coMULTI">/* Register a user-defined signal handler. */</span>
    signal<span class="br0">(</span><a href="SIG_types.html"><span class="kw502">SIGABRT</span></a>, signal_handler<span class="br0">)</span><span class="sy4">;</span>
    signal<span class="br0">(</span><a href="SIG_types.html"><span class="kw503">SIGFPE</span></a>,  signal_handler<span class="br0">)</span><span class="sy4">;</span>
    signal<span class="br0">(</span><a href="SIG_types.html"><span class="kw504">SIGILL</span></a>,  signal_handler<span class="br0">)</span><span class="sy4">;</span>
    signal<span class="br0">(</span><a href="SIG_types.html"><span class="kw505">SIGINT</span></a>,  signal_handler<span class="br0">)</span><span class="sy4">;</span>
    signal<span class="br0">(</span><a href="SIG_types.html"><span class="kw506">SIGSEGV</span></a>, signal_handler<span class="br0">)</span><span class="sy4">;</span>
    signal<span class="br0">(</span><a href="SIG_types.html"><span class="kw507">SIGTERM</span></a>, signal_handler<span class="br0">)</span><span class="sy4">;</span>
 
    <span class="coMULTI">/* Raise a signal. */</span>
    <a href="raise.html"><span class="kw497">raise</span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw502">SIGABRT</span></a><span class="br0">)</span><span class="sy4">;</span>
    <a href="raise.html"><span class="kw497">raise</span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw503">SIGFPE</span></a><span class="br0">)</span><span class="sy4">;</span>
    <a href="raise.html"><span class="kw497">raise</span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw504">SIGILL</span></a><span class="br0">)</span><span class="sy4">;</span>
    <a href="raise.html"><span class="kw497">raise</span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw505">SIGINT</span></a><span class="br0">)</span><span class="sy4">;</span>
    <a href="raise.html"><span class="kw497">raise</span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw506">SIGSEGV</span></a><span class="br0">)</span><span class="sy4">;</span>
    <a href="raise.html"><span class="kw497">raise</span></a><span class="br0">(</span><a href="SIG_types.html"><span class="kw507">SIGTERM</span></a><span class="br0">)</span><span class="sy4">;</span>
 
    <span class="kw1">return</span> <span class="nu0">0</span><span class="sy4">;</span>
<span class="br0">}</span></pre></div></div>
<p>Output:
</p>
<div dir="ltr" class="mw-geshi" style="text-align: left;"><div class="text source-text"><pre class="de1">Process SIGABRT signal here.
Process SIGFPE  signal here.
Process SIGILL  signal here.
Process SIGINT  signal here.
Process SIGSEGV signal here.
Process SIGTERM signal here.</pre></div></div> 
</div>
<h3>
<span class="editsection">[<a href="http%3A//en.cppreference.com/mwiki/index.php" title="Edit section: See also">edit</a>]</span> <span class="mw-headline" id="See_also">See also</span>
</h3>
<table class="t-dsc-begin">

<tr class="t-dsc-sep">
<td colspan="2">
</td>
</tr>
<tr class="t-dsc">
<td>  <div class="t-dsc-member-div"><div><a href="raise.html" title="c/program/raise"> <span class="t-lines"><span>raise</span></span></a></div></div>
</td>
<td>   runs the signal handler for particular signal  <br> <span class="t-mark">(function)</span> 
</td>
</tr>

<tr class="t-dsc-sep">
<td colspan="2">
</td>
</tr>
<tr class="t-dsc">
<td colspan="2"> <div class="t-dsc-see">
<span><a href="../../cpp/utility/program/signal.html" title="cpp/utility/program/signal">C++ documentation</a></span> for <span class="t-dsc-see-tt"><span>signal</span></span>
</div>
</td>
</tr>

</table>

<!-- 
NewPP limit report
Preprocessor visited node count: 2450/1000000
Preprocessor generated node count: 6529/1000000
Post‐expand include size: 60144/2097152 bytes
Template argument size: 12942/2097152 bytes
Highest expansion depth: 21/40
Expensive parser function count: 0/100
-->

<!-- Saved in parser cache with key mwiki1-mwiki_en_:pcache:idhash:6183-0!*!0!!en!*!* and timestamp 20140419150355 -->
</div>                    <!-- /bodycontent -->
                                        <!-- printfooter -->
                    <div class="printfooter">
                    Retrieved from "<a href="http%3A//en.cppreference.com/mwiki/index.php">http://en.cppreference.com/mwiki/index.php?title=c/program/signal&amp;oldid=69680</a>"                    </div>
                    <!-- /printfooter -->
                                                            <!-- catlinks -->
                    <div id="catlinks" class="catlinks catlinks-allhidden"></div>                    <!-- /catlinks -->
                                                            <div class="visualClear"></div>
                    <!-- debughtml -->
                                        <!-- /debughtml -->
                </div>
                <!-- /bodyContent -->
            </div>
        </div>
        <!-- /content -->
        <!-- footer -->
        
        <!-- /footer -->
        <script>if(window.mw){
mw.loader.state({"site":"loading","user":"missing","user.groups":"ready"});
}</script>
<script src="../../../common/skin_scripts.js"></script>
<script>if(window.mw){
mw.loader.load(["mediawiki.action.view.postEdit","mediawiki.user","mediawiki.page.ready","mediawiki.searchSuggest","mediawiki.hidpi","ext.gadget.ColiruCompiler"], null, true);
}</script>
<script src="../../../common/site_scripts.js"></script>

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2828341-1']);
_gaq.push(['_setDomainName', 'cppreference.com']);
_gaq.push(['_trackPageview']);
</script><!-- Served in 0.084 secs. -->
	</body>
<!-- Cached 20140419160446 -->
</html>
